/* Deals a random hand of cards */
/* 自己尝试了使用字符串 */
#include <stdbool.h>  /* C99 only */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM_SUITS 4
#define NUM_RANKS 13
int main(void)
{
    bool in_hand[NUM_SUITS][NUM_RANKS] = {false};
    int num_cards, rank, suit;
    const char* rank_code[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
    const char* suit_code[] = {"黑桃", "红桃", "草花", "方块"};
    srand((unsigned) time(NULL));
    printf("Enter number of cards in hand: ");
    scanf("%d", &num_cards);
    printf("Your hand:");
    while (num_cards > 0) {
        suit = rand() % NUM_SUITS;  /* picks a random suit */
        rank = rand() % NUM_RANKS;  /* picks a random rank */
        if (!in_hand[suit][rank]) {
            in_hand[suit][rank] = true;
            num_cards--;
            printf(" %s%s", suit_code[suit], rank_code[rank]);
        }
    }
    printf("\n");
    return 0;
}